from src.modules.knowbase.repository.dao.textvector_dao import TextVectorDao
from sqlalchemy.ext.asyncio import AsyncSession
from typing import List
from src.modules.ai_models.model_loaders.model_loader import get_text_embedding_model

class TextVectorService:
    @staticmethod
    async def get_textvector_list(user_id:str =None,
                                  file_id: str = None,
                                  kb_id: str = None,
                                  page: int = 1, page_size: int = 10)->dict:
        return await TextVectorDao.get_textvector_list(
            user_id, file_id, kb_id, page, page_size
        )

    @staticmethod
    async def get_text_vector_list_for_rag(question_vector: List[float],
                                           session: AsyncSession,
                                           knowbase_ids: List[str],
                                           top_k: int):
        return await TextVectorDao.get_textvector_list_for_rag(question_vector=question_vector,
                                                               session=session,
                                                               knowbase_ids=knowbase_ids,
                                                               top_k=top_k)

    @staticmethod
    async def delete_vector(vector_id:str):
        return await TextVectorDao.delete_vector(vector_id)


    @staticmethod
    async def update_text_vector_by_id(vector_id:str,text_content:str):
        text_embedding_model = get_text_embedding_model()
        text_vector = text_embedding_model.get_text_embedding(text_content)
        return await TextVectorDao.update_text_vector_by_id(vector_id,text_content,text_vector)
